function scriptGlobal_PLI_RvsIm

rootDir='C:\Users\matthew\Desktop\2012\projects\RealAndImaginery\results\pli_REST_TASK\relativePLI\';
outDir='';
bandNames={'theta','alpha','beta','gamma'};
conditions={'Ileft','Iright','Rleft','Rright'};

inDir=rootDir%fullfile(rootDir,bandNames{1});
fileName=strcat(bandNames{1},'_');
fileToLoad=strcat(fileName,conditions{1});
load(fullfile(inDir,fileToLoad)); 
nSubjs=size(relPLI_subjXchXch,1);
nCh=size(relPLI_subjXchXch,2);

gPLI_bandXsubjXcond=zeros(length(bandNames),nSubjs,length(conditions));

for i=1:length(bandNames)
    
    %inDir=fullfile(rootDir,bandNames{i});
    
    fileName=strcat(bandNames{i},'_');
    for j=1:length(conditions)
        fileToLoad=strcat(fileName,conditions{j});
        load(fullfile(inDir,fileToLoad)); 
        gPLI_bandXsubjXcond(i,:,j)=globalPLI(relPLI_subjXchXch);
    end


end


statANDplot(gPLI_bandXsubjXcond,bandNames,conditions);


function statANDplot(gPLI_bandXsubjXcond,bandNames,conditions)
meanBars=zeros(size(gPLI_bandXsubjXcond,1),size(gPLI_bandXsubjXcond,3))
stdBars=zeros(size(gPLI_bandXsubjXcond,1),size(gPLI_bandXsubjXcond,3))

for i=1:size(gPLI_bandXsubjXcond,1)
    meanBars(i,:)=mean(squeeze(gPLI_bandXsubjXcond(i,:,:)),1);
    stdBars(i,:)=std(squeeze(gPLI_bandXsubjXcond(i,:,:)),0,1);
    [p{i},anovatab{i},st{i}] = anova1(squeeze(gPLI_bandXsubjXcond(i,:,:)),conditions,'off');
    figure;
    boxplot(squeeze(gPLI_bandXsubjXcond(i,:,:)));
    title(gca,strcat(bandNames{i},strcat('----p-value--->',num2str(p{i}))))
    figure;
    [c{i},m{i},h{i},nms{i}] = multcompare(st{i},'display','on');
    title(gca,bandNames{i})
    
end
stdErrBars=stdBars./sqrt(size(gPLI_bandXsubjXcond,2));
figure;
barweb(meanBars,stdBars,1,bandNames,'GLOBAL PLI','BANDS','avg PLI',[],[],conditions,1,'axis');


